package com.itheima.aop;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

@Component
@Aspect
public class MyAdvice {
    @Pointcut("execution(* *..*(..))")
    public void pt(){}

    //@Before("pt()")
    public void before(){
        System.out.println("before ...");
    }

    //@After("pt()")
    public void after(){
        System.out.println("after ...");
    }

    //@AfterReturning("pt()")
    public void afterReturning(){
        System.out.println("afterReturning ...");
    }

    //@AfterThrowing("pt()")
    public void afterThrowing(){
        System.out.println("afterThrowing ...");
    }

    @Around("pt()")
    public Object arround(ProceedingJoinPoint pjp) throws Throwable {
        Object result = null;
        System.out.println("around before...");
       /* try {
            result = pjp.proceed();
        } catch (Throwable throwable) {
            System.out.println("exception "+throwable.getMessage());
        }*/
        result = pjp.proceed();
        System.out.println("around after ..."+result);
        return result;
    }
}
